<?php

namespace app\admin\model\xiluedu;

use app\admin\model\User;
use think\Exception;
use think\Model;


class VipOrder extends Model
{

    

    

    // 表名
    protected $name = 'xiluedu_vip_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'pay_status_text',
        'paytime_text',
        'vip_unit_text'
    ];
    
    public function getPayStatusList()
    {
        return ['0' => __('Pay_status 0'), '1' => __('Pay_status 1')];
    }

    public function getVipUnitList()
    {
        return ['1' => __('Vip_unit 1'), '2' => __('Vip_unit 2'), '3' => __('Vip_unit 3')];
    }


    public function getPayStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_status']) ? $data['pay_status'] : '');
        $list = $this->getPayStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPaytimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getVipUnitTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['vip_unit']) ? $data['vip_unit'] : '');
        $list = $this->getVipUnitList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function user(){
        return $this->belongsTo(User::class,'user_id','id',[],'LEFT')->setEagerlyType(0);
    }

}
